#include "ga.h"

#include "population.h"
#include "config.h"


//------------------------------------------------------------------------------
// Public functions

Ga::Ga()
{
    init();
}

Ga::~Ga()
{
    if(m_population) {
        delete m_population;
        m_population = NULL;
    }
    
}

void Ga::start()
{
    // Run the algorithm for a defined number of generations.
    m_population->evolve(P_GENERATIONS);
}


//------------------------------------------------------------------------------
// Private Functions

void Ga::init()
{
    // Population params.
    m_population_size = P_SIZE;

    // Individual params.
    m_mutation_rate = P_MUTATION;
    m_crossover_rate = P_CROSSOVER;

    // Create the population
    m_population = new Population(m_population_size, m_crossover_rate, 
        m_mutation_rate);
}
